var pageii = null;
var grid = null;
$(function() {

	grid = lyGrid({
		pagId : 'paging',
		l_column : [{
			colkey : "gname",
			name : "宿舍名称"
		},{
			colkey : "staffMaps",
			name : "住宿人",
			renderData : function(rowindex,data, rowdata, column) {
				var name="";
				$.each(data,function(i,v){
					name=v.name;
					return name;
				});
				return name;
			}
		},{
			colkey : "staffMaps",
			name : "部门",
			renderData : function(rowindex,data, rowdata, column) {
				var dname="";
				$.each(data,function(i,v){
					dname=v.dname;
					return dname;
				});
				return dname;
			}
		},{
			colkey : "degree",
			name : "用电度数",
			
		},{
			colkey : "money",
			name : "金额",
			
		},{
			colkey : "remake",
			name : "备注",
		}],
		jsonUrl : rootPath + '/hrelectricity/electricity_findByPage.shtml',
		dymCol:true,
		checkbox : true,
		serNumber : false
	});
	$("#addOrder").click("click", function() {
		addAccount();
	});
	$("#addOrders").click("click", function() {
		addAccounts();
	});
	$("#editOrder").click("click", function() {
		editAccount();
	});
	$("#delFunss").click("click", function() {
		delAccount();
	});
	$("#delFuns").click("click", function() {
		delAccounts();
	});
	$("#details").click("click", function() {
		particulars();
	});
	$("#search").click("click", function() {// 绑定查询按扭
		
		var searchParams = $("#searchForm").serializeJson();
		grid.setOptions({
			data : searchParams
			
		});
	});
	
});





function editAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "编辑电费统计信息",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/hrelectricity/electricity_edit.shtml?id=' + cbox
	});
}
function addAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "新增宿舍人员",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/hrelectricity/electricityPeople_add.shtml?id=' + cbox
	});
}
function addAccounts() {
	pageii = layer.open({
		title : "新增电费统计信息",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/hrelectricity/electricity_add.shtml'
	});
}

function delAccounts() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "删除宿舍人员",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/hrelectricity/electricityPeople_delete.shtml?id=' + cbox
	});
}
/*详情展示
 */
function particulars() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox.length > 1) {
		layer.msg("只能选中一个");
		return;
	}
	if(cbox == ""){
		layer.msg("需要选择一个");
		return;
	}
	pageii = layer.open({
		title : "培训",
		type : 2,
		area : [ "800px", "100%" ],
		content : rootPath + '/hrelectricity/electricity_particulars.shtml?id=' + cbox
	});
}
function delAccount() {
	var cbox = grid.getSelectedCheckbox();
	if (cbox == "") {
		layer.msg("请选择删除项！！");
		return;
	}
	layer.confirm('是否删除？', function(index) {
		var url = rootPath + '/hrelectricity/electricityDormitory_deleteEntity.shtml';
		var s = CommnUtil.ajax(url, {
			ids : cbox.join(",")
		}, "json");
		if (s == "success") {
			layer.msg('删除成功');
			grid.loadData();
		} else {
			layer.msg('删除失败');
		}
	});
	
}